//@charset "utf-8";
define(function(require, exports, module) {
	var _ = require('_');
	var plateListModel = require('../models/platelist');
	var QuerySearchModel = require('../models/querysearch');
	var storageModel = require('../models/storage.js');
	var commonMethod = require('../lib/common');
	var CodeListModel = require('../models/codelist');
	// var NoPromptModel = require('../models/noprompt');
	var BaseView = require('../views/base');
	var baseView = new BaseView();
	var PlateListView = BaseView.extend({
		el: '#sidebarbox, .tip-win-plate',
		plateTemplate: _.template($('#template_plate').html()),
		plateNames: [],
		stockList: [],
		events: {
			'mouseenter .items': 'hoverItems',
			'mouseleave .items': 'hideItems',
			'click .items-name': 'jumpPlate',
			'click #new-plate': 'showNewPlate',
			'click #dynamic-new-plate': "showDyanmicNewPlate",
			'click #span-cancel-add-plate, #span-close-add-plate': 'hideAddPlate',
			'click .span-plate-delete': 'showTipWinDetelePlate',
			'click #tip_win_submit': 'deletePlate',
			'click #tip_win_cancel': 'cancelDelete',
			'click .span-plate-rename': 'showTipWinRenamePlate',
			'click .span-plate-rename-realtime': 'showTipWinRenamePlateRealtime',
			'click #rename_win_cancel, #rename_win_close': 'hideRenamePlateWin',
			'click #rename_win_submit': 'savePlateRename',
			'change #input-add-plate-content': 'changeAddPlateContent',
			'click #span-submit-add-plate': 'addPlateCreate',
			'click #span-submit-add-dynamic-plate': 'addDynamicPlate',
			'click #span-cancel-add-dynamic-plate, #span-close-add-dynamic-plate': 'hideAddPlate',
			'click .items-update-click': 'modifyNeedUpdate',
			'click #rename_win_cancel_realtime, #rename_win_close_realtime': 'hideRenamePlateWinRealtime',
			'click #rename_win_submit_realtime': 'savePlateRenameRealtime',
			'click #operate-plate': 'togglePlateList',
			'click #dynamic-operate-plate': 'toggleDynamicPlateList'
		},
		initialize: function() {
			var self = this;

			self.requestPlateList();

			setInterval(function() {
				//定时同步动态板块的状态，使用定时器代替推送
				self.syncRequestPlateList();
			}, 2000);

			plateListModel.registerCustomBlockUpdatePush(self, self.ustomBlockUpdate);

			// 回车保存
			$('#rename_win_input, #input-add-plate-content').keypress(function(e) {
				e = e || window.event;
				if (e.keyCode == 13) {
					if ($(e.currentTarget).attr('status') === 'add') {
						self.savePlateCreate();
					} else {
						self.savePlateRename();
					}
				}
			});
			$('#rename_win_input_realtime').keypress(function(e) {
				e = e || window.event;
				if (e.keyCode == 13) {
					if ($(e.currentTarget).attr('status') !== 'add') {
						self.savePlateRenameRealtime();
					}
				}
			});


			// 创建实时更新板块
			$('#view_result_condition_create,#create-stocks').live('click', function(e) {
				e = e || window.event;
				var $dom = $(e.currentTarget);
				var changeType = parseInt($dom.attr('data-change'));
				// var dataId = $dom.attr('data-id');
				if (changeType !== 1) {
					var condition = $('#view_searchinput').val();
					if (condition.replace(/\s/g, '') === $('#view_searchinput').attr('data-placeholder')) {
						return;
					}
					if ($('.view_second_option.selected').length) {
						var secondList = [];
						secondList.push(condition);
						$('.view_second_option.selected').each(function() {
							secondList.push($(this).html());
						});
						condition = secondList.join(";");
					}
					self.showAddDynamicPlate(condition);
				} else {
					var dataId = $dom.attr('data-id');
					var name = $("#view-a-data-id-" + dataId).attr('title');
					$("#tip_win_rename_plate_realtime").show();
					$("#rename_win_data_id_realtime").val(dataId);
					$("#rename_win_input_realtime").val(name);
					$("#rename_win_oldname_realtime").val(name);
					$("#rename_win_input_realtime").focusEnd();
					$('#div-mask').show();
				}

			});

			// document.onmousemove = function(ev) {
			// 	$('#save_input').val(1);
			// };
			$(document).mousemove(function(ev) {
				if (ev.pageX < 178 && ev.pageY > 30) {
					$('#slide_list').show();
				} else {
					$('#slide_list').hide();
				}
			});

			baseView.renderScrollSlider();
		},
		mouseMove: function(ev) {
			$('#save_input').val(1);
			ev = ev || window.event;
			var mousePos = this.mousePosition(ev);
			// $('#save_input').val(mousePos.x);
			// document.getElementById('xxx').value = mousePos.x;
			// document.getElementById('yyy').value = mousePos.y;
		},
		mousePosition: function(ev) {
			if (ev.pageX || ev.pageY) {
				return {
					x: ev.pageX,
					y: ev.pageY
				};
			}
			return {
				x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
				y: ev.clientY + document.body.scrollTop - document.body.clientTop
			};
		},
		requestPlateList: function() {
			var self = this;
			// 渲染板块股
			plateListModel.requestList(function(data) {
				var platelistDom = '';
				var dynamicplatelistDom = '';

				// alert(JSON.stringify(data));
				$.each(data, function(i, item) {
					self.plateNames.push(item.name);

					//COCO新增--用来判断标题应该是什么

					if(item.id == baseView.getQuery('plateid')){
						$('#defaultView').hide();
						baseView.changeTitle('添加股票至“'+item.name+'”',function(){

							QuerySearchModel.getQueryResult('昨日加自选股前十的股票', function() {

								self.renderTenStock(item.id);
							});

						});
					}
					if (i === 0) {
						platelistDom += self.plateTemplate({
							type: 'optional', // 自选股板块
							id: item.id,
							num: '(' + item.num + ')',
							showtxt: self.showtxt(item.name),
							inputtxt: commonMethod.escapeHtml(item.name),
							update: plateListModel.isCustomBlockNeedUpdate(item.id)
						});
						return;
					}
					if (i <= 8) {
						platelistDom += self.plateTemplate({
							type: 'fixed', // 固定的8个板块
							id: item.id,
							num: '(' + item.num + ')',
							showtxt: self.showtxt(item.name),
							inputtxt: commonMethod.escapeHtml(item.name),
							update: plateListModel.isCustomBlockNeedUpdate(item.id)
						});
						return;
					}
					//isSelect这个字段表示什么 1是动态板块 0是默认板块
					if (item.isSelect === 0) {
						platelistDom += self.plateTemplate({
							type: 'default',
							id: item.id,
							num: '(' + item.num + ')',
							showtxt: self.showtxt(item.name),
							inputtxt: commonMethod.escapeHtml(item.name),
							update: plateListModel.isCustomBlockNeedUpdate(item.id)
						});
					} else if (item.isSelect === 1) {
						dynamicplatelistDom += self.plateTemplate({
							type: 'realtime',
							id: item.id,
							num: '(' + item.num + ')',
							showtxt: self.showtxt(item.name),
							inputtxt: commonMethod.escapeHtml(item.name),
							update: plateListModel.isCustomBlockNeedUpdate(item.id)
						});
					}
				});
				$('#sidebarbox-items').html(platelistDom);
				$('#dynamic-sidebarbox-items').html(dynamicplatelistDom);
			});

		},

		renderTenStock:function(plateid){
			var self = this;
			var result = QuerySearchModel.get('result');
			if(result == ''){return;}
			var data = result.data;
			
			var selectedCodeList = CodeListModel.getCodeList();
			// alert(JSON.stringify(selectedCodeList));
			var tpml = '<div class="ten-stock-title">' +
				'<p>昨日加自选前十的个股：</p>' +
				'</div>' +
				'<div class="clearfix">' +
				'<table class="ten-stock">' +
				'<colgroup width="10%" />' +
				'<colgroup width="45%" />' +
				'<colgroup width="45%" />' +
				'<tbody>';
			for (var i in result.data) {
				var isSelected = false;
				if (1 === selectedCodeList[data[i]['code']]) {
					isSelected = true;
				}
				tpml += '<tr data-stock="' + data[i]['code'] + '" view_dbl_query_search="' + data[i]['code'] + '">' +
					'<td><input type="checkbox" ' + (isSelected ? 'checked' : '') + ' value_code="' + data[i]['code'] + '"></td>' +
					'<td>' + data[i]['code'] + '</td>' +
					'<td>' + data[i]['zqmc'] + '</td>' +
					'</tr>';

				if (i == 4) {
					tpml += '</tbody>' +
						'</table >' +
						'<table class="ten-stock ml60">' +
						'<colgroup width="10%" />' +
						'<colgroup width="45%" />' +
						'<colgroup width="45%" />' +
						'<tbody>';
				}
			}
			tpml += '</table></div>';

			$('#tenstock').append(tpml);
			self.trListener(plateid);
			// alert(result.codelist);

		},
		//监听tr的点击事件
		trListener:function(plateid){
			var self = this;
			$('#tenstock table').on({
				click: function(e) {

					var target = $(e.target);
					var tagName = target[0].nodeName.toLowerCase();
					var tr = target.closest('tr');
					var code = [tr.attr('data-stock') + ""];
					var input = tr.find('input[type="checkbox"]');
					var checked = input.is(':checked');

					if(checked){
						if(tagName == 'input'){
							self.addPlate(plateid,code);
							return;
						}
						input.prop('checked',false);
						baseView.deletePlateStock(plateid,code);
					}else{

						if(tagName == 'input'){
							baseView.deletePlateStock(plateid,code);
							return;
						}
						input.prop('checked',true);
						self.addPlate(plateid,code);

					}
				}
			});
		},
		addPlate:function(plateid,code){

			CodeListModel.addCodeList(code);
			//$('#save_input').val($('html').html());
			var codelist = CodeListModel.getCodeListStr();

			baseView.savePlateAdd(plateid, codelist, $("#items-data-id-"+plateid));
		},
		deletePlateStock:function(plateid,code){
			try{
				var Util = external.createObject('Util');
				Util.deleteCustomBlockStock(plateid,code);
			}catch(e){}

		},
		showTipWinDetelePlate: function(e) {
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			this.savePlateDelete(dataId, $('#items-data-id-' + dataId));
			// $('#div-mask').show();
			// $('#tip_win_submit').attr('data-id', dataId);
			// $("#tip_win_delete_plate").show();
			TA.log({
				id: '579099db_308'
			});
		},
		cancelDelete: function() {
			$('#div-mask').hide();
			$('#tip_win_submit').attr('data-id', '');
			$("#tip_win_delete_plate").hide();
		},
		deletePlate: function(e) {
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			this.savePlateDelete(dataId, $('#items-data-id-' + dataId));
			this.cancelDelete();
			TA.log({
				id: 'cop_581206ee_248'
			});
		},
		savePlateRename: function() {
			var self = this;
			var newname = $("#rename_win_input").val();
			var plateId = $("#rename_win_data_id").val();
			var oldname = $("#rename_win_oldname").val();

			this.plateNames = commonMethod.arrRemove(this.plateNames, oldname);
			var nameObj = plateListModel.formatPlateName(this.plateNames, newname);
			newname = nameObj.newname;
			this.plateNames = nameObj.platenames;
			plateListModel.requestRename(plateId, newname, function(isOk) {
				if (isOk) {
					$("#view-a-data-id-" + plateId).attr('title', newname);
					$("#view-a-data-id-" + plateId).text(self.showtxt(newname));
					self.plateNames = nameObj.platenames;
				} else {
					$("#view-a-data-id-" + plateId).attr('title', oldname);
					$("#view-a-data-id-" + plateId).text(self.showtxt(oldname));
					self.plateNames.push(oldname);
				}
			});

			self.hideRenamePlateWin();
			TA.log({
				id: 'cop_5812079a_304'
			});
		},
		savePlateCreate: function(name, codelist, type) { // 实时板块传参
			var self = this;
			codelist = codelist || '';
			name = name || '';
			var condition = '';
			if (type === 1 && name) { // 创建实时（含板块股）
				condition = $('#input-add-plate-content-dynamic').val();
			}
			name = name || $('#input-add-plate-content').val();
			var nameObj = plateListModel.formatPlateName(this.plateNames, name);
			this.plateNames = nameObj.platenames;
			name = nameObj.newname;
			plateListModel.requestCreate(name, condition, function(id) {
				if (id) {
					if (codelist.length > 0) {
						self.savePlateAdd(id, codelist);
					}
					self.requestPlateList();
					self.showtip("板块创建成功！");
					$('.choose').removeClass('choose');
					$('#items-name-data-id-' + id).addClass('choose');
				} else { //创建失败
					self.showtip("超过板块上限100，创建失败！");
				}
				$('#sidebarbox-items').scrollTop(9999);
			});
			self.hideAddPlate();
		},
		savePlateDelete: function(id, $dom) {
			var self = this;

			plateListModel.requestDelete(id, function(isOk) {
				if (isOk) {
					self.removePlate($dom);
					self.plateNames = plateListModel.removePlateName(self.plateNames, $dom.find('input').val());
				} else {
					self.showtip("板块删除失败！");
				}
			});
		},
		removePlate: function($dom) {
			$dom.remove();
		},
		// 板块名显示长度处理
		showtxt: function(txt) {
			var len = 0;
			var resultTxt = '';
			for (var i = 0; i < txt.length; i++) { // 汉字2字节  7*2
				if (len >= 14) {
					resultTxt += '...';
					return resultTxt;
				}
				if (txt.charCodeAt(i) > 127 || txt.charCodeAt(i) == 94) {
					len += 2;
				} else {
					len += 1;
				}
				resultTxt += txt.charAt(i);
			}
			return resultTxt;
		},
		jumpPlate: function(e) {
			TA.log({
				id: '57909a17_618'
			});
			baseView.changeTitle('自定义板块');
			var $dom = $(e.currentTarget);
			// $dom.find('.ico-update').remove();
			$('.choose').removeClass('choose');
			$dom.addClass('choose');
			plateListModel.jumpPlate($dom.attr('data-id'));
		},
		changeAddPlateContent: function() {
			$('#input-add-plate-content-default').val("");
		},
		showNewPlate: function() {
			baseView.changeTitle('自定义板块');
			$('#div-mask').show();
			//TODO:
			$('#input-add-plate-content').val("请输入板块名");
			$('#tip_win_add_plate').show();
			$('#input-add-plate-content').focusEnd();
			TA.log({
				id: '579098d2_466'
			});
		},
		showDyanmicNewPlate: function () {
			// kuck新增 重置按钮上的文字 清除按钮上的状态
			$('#view_result_condition_create').html('创建条件为动态板块').attr('data-change', '0');
			baseView.changeTitle('自定义板块');

			$('#view_searchinput').val('');
			$("#view_select_option").hide();
			$('#view_select_option_container').hide();
			//$('#view_search_options_relation').show();
			$("#defaultView").show();
			$('#operate').hide();
			$('#resultStockView').hide();
			$('#view_result_condition').hide();
			$('#view_clearbtn').hide();
			$('#noResultView').hide();
			$('#view_search_options_relation').hide();

			//COCO新增--当有plateid时--》点击叉叉出现昨日前十板块
			if(baseView.getQuery('plateid')){
				$("#defaultView").hide();
				$('#tenstock').show();
			}
			baseView.flash();
		},
		hideAddPlate: function() {
			$('#div-mask').hide();
			$('#input-add-plate-content').val('');
			$('#tip_win_add_plate').hide();

			//动态板块
			$('#input-add-plate-dynamic-content').val('');
			$('#tip-win-add-dynamic-plate').hide();
			$('#noprompt-add-dynamic-plate').attr('checked', false);
		},
		hoverItems: function(e) {
			//鼠标经过效果
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			$("#operate-data-id-" + dataId).show();
			$("#operatemore-data-id-" + dataId).show();
			$("#items-name-data-id-" + dataId).addClass('mouseEnter');
		},
		hideItems: function(e) {
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			$("#operate-data-id-" + dataId).hide();
			$("#operatemore-data-id-" + dataId).hide();
			$("#items-name-data-id-" + dataId).removeClass('mouseEnter');
		},
		showTipWinRenamePlate: function(e) {
			baseView.changeTitle('自定义板块');
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			var name = $("#view-a-data-id-" + dataId).attr('title');
			$("#tip_win_rename_plate").show();
			$("#rename_win_data_id").val(dataId);
			$("#rename_win_input").val(name);
			$("#rename_win_oldname").val(name);
			$("#rename_win_input").focusEnd();
			$('#div-mask').show();
			TA.log({
				id: '579099c5_9'
			});
		},
		hideRenamePlateWin: function() {
			$("#tip_win_rename_plate").hide();
			$("#rename_win_data_id").val('');
			$("#rename_win_input").val('');
			$("#rename_win_oldname").val('');
			$('#div-mask').hide();
		},
		addPlateCreate: function() {
			TA.log({
				id: 'cop_581200a2_699'
			});
			var self = this;
			var name = $('#input-add-plate-content').val();
			if ($('#input-add-plate-content-default').val() !== "") {
				name = $('#input-add-plate-content-default').val();
			}
			if (name === '') {
				return;
			}
			self.savePlateCreate(name);
		},
		showAddDynamicPlate: function(condition) {
			var self = this;
			if (plateListModel.isShowCreateQueryBlock()) {
				$('#div-mask').show();
				$('#input-add-plate-name-dynamic').val(condition);
				$('#input-add-plate-content-dynamic').val(condition);
				$('#tip-win-add-dynamic-plate').show();
				$('#input-add-plate-name-dynamic').focusEnd();
			} else {
				$('#input-add-plate-content-dynamic').val(condition);
				var data = QuerySearchModel.get('result').data;
				var codelist = [];
				$.each(data, function(i, obj) {
					codelist.push(obj.code);
				});
				self.savePlateCreate(condition, codelist, 1);
				TA.log({
					id: '579098fd_342'
				});
			}
		},
		//修改（冻结/开启）动态更新
		modifyNeedUpdate: function(e) {
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			var updateStatus = $dom.attr('update-status');
			updateStatus = updateStatus === '0' ? true : false;
			try {
				plateListModel.enableCustomBlockUpdate(parseInt(dataId), updateStatus);
				if (updateStatus === true) {
					$dom.attr('update-status', 1);
					$dom.removeClass('items-update0');
					$dom.addClass('items-update1');
					$dom.attr("title", "关闭更新状态");
					TA.log({
						id: 'cop_58120933_193'
					});
				} else {
					$dom.attr('update-status', 0);
					$dom.removeClass('items-update1');
					$dom.addClass('items-update0');
					$dom.attr("title", "开启更新状态");
					TA.log({
						id: 'cop_5812094f_730'
					});
				}
			} catch (e) {

			}
		},
		//执行添加动态版块
		addDynamicPlate: function() {
			var self = this;
			var data = QuerySearchModel.get('result').data;
			var codelist = [];
			$.each(data, function(i, obj) {
				codelist.push(obj.code);
			});
			var name = $("#input-add-plate-name-dynamic").val();
			if ($("#noprompt-add-dynamic-plate").attr("checked") == "checked") {
				plateListModel.enableShowCreateQueryBlock(false);
			}
			self.savePlateCreate(name, codelist, 1);
			TA.log({
				id: '579098fd_342'
			});
		},
		showTipWinRenamePlateRealtime: function(e) {
			e = e || window.event;
			var $dom = $(e.currentTarget);
			var dataId = $dom.attr('data-id');
			var query = plateListModel.getCustomBlockQuery(dataId);
			$('#view_searchinput').val(query).focusEnd();
			$('#view_searchbtn').click();
			$('#view_result_condition_create').html('确定修改条件').attr("data-change", 1).attr('data-id', dataId);
			var title = $('#view-a-data-id-' + dataId).attr('title');
			baseView.changeTitle('修改动态板块“' + title + '”');
			baseView.flash();

			TA.log({
				id: '579099c5_9'
			});
		},
		hideRenamePlateWinRealtime: function() {
			$("#tip_win_rename_plate_realtime").hide();
			$("#rename_win_data_id_realtime").val('');
			$("#rename_win_input_realtime").val('');
			$("#rename_win_oldname_realtime").val('');
			$('#div-mask').hide();
		},
		savePlateRenameRealtime: function() {
			var self = this;
			// kuck add
			var queryStr = $("#view_searchinput").val();
			var newname = $("#rename_win_input_realtime").val();
			var plateId = $("#rename_win_data_id_realtime").val();
			var oldname = $("#rename_win_oldname_realtime").val();
			plateListModel.setCustomBlockQuery(plateId, queryStr);
			// var newquery = $("#requery_win_input_realtime").val();
			// var oldquery = $("#requery_win_oldquery_realtime").val();
			this.plateNames = commonMethod.arrRemove(this.plateNames, oldname);
			var nameObj = plateListModel.formatPlateName(this.plateNames, newname);
			newname = nameObj.newname;
			this.plateNames = nameObj.platenames;
			plateListModel.requestRename(plateId, newname, function(isOk) {
				if (isOk) {
					$("#view-a-data-id-" + plateId).attr('title', newname);
					$("#view-a-data-id-" + plateId).text(self.showtxt(newname));
					self.plateNames = nameObj.platenames;
				} else {
					$("#view-a-data-id-" + plateId).attr('title', oldname);
					$("#view-a-data-id-" + plateId).text(self.showtxt(oldname));
					self.plateNames.push(oldname);
				}
			});
			// plateListModel.setCustomBlockQuery(plateId, newquery);

			self.hideRenamePlateWinRealtime();
			baseView.showtip();
			TA.log({
				id: 'cop_5812079a_304'
			});
		},
		//同步板块是否开启动态更新状态
		syncRequestPlateList: function() {
			$(".items-update-click").each(function() {
				var plateId = $(this).attr("data-id");
				var status = plateListModel.isCustomBlockNeedUpdate(plateId);
				if (status != $(this).attr("update-status")) {
					$(this).removeClass("items-update0");
					$(this).removeClass("items-update1");
					$(this).addClass("items-update" + status);
					$(this).attr("update-status", status);
				}
			});
		},
		ustomBlockUpdate: function(self, rst) {
			var obj = eval("(" + rst + ")");
			var $dom = $('#items-name-data-id-' + obj.id);
			if (obj.event == 'mod') {
				if (obj.num !== undefined) {
					var newtext = '(' + obj.num + ')';

					if ($dom.find('.num').text() === newtext) {
						return;
					}

					if ($dom.find('.ico-update').length === 0) {
						$dom.append('<span class="ico ico-update"></span>');
						setTimeout(function() {
							$dom.find('.ico-update').remove();
						}, 1500);
					}
					$dom.find('.num').text(newtext);
				}
				if (obj.name !== undefined) {
					var newName = obj.name;

					if ($('#view-a-data-id-' + obj.id).text() === newName) {
						return;
					}

					if ($dom.find('.ico-update').length === 0) {
						$dom.append('<span class="ico ico-update"></span>');
						setTimeout(function() {
							$dom.find('.ico-update').remove();
						}, 1500);
					}
					self.plateNames = commonMethod.arrRemove(self.plateNames, $('#view-a-data-id-' + obj.id).attr('title'));
					var nameObj = plateListModel.formatPlateName(self.plateNames, newName);
					$('#view-a-data-id-' + obj.id).text(self.showtxt(nameObj.newname));
					$('#view-a-data-id-' + obj.id).attr('title', nameObj.newname);
				}
			} else if (obj.event == 'new') {
				var nameObj = plateListModel.formatPlateName(self.plateNames, obj.name);
				self.plateNames = nameObj.platenames;
				var type = '';
				if (obj.isSelect === 0) {
					type = 'default';
				} else if (obj.isSelect === 1) {
					type = 'realtime';
				}
				var addHtml = self.plateTemplate({
					type: type, // 自选股板块
					id: obj.id,
					num: '(' + obj.num + ')',
					showtxt: self.showtxt(nameObj.newname),
					inputtxt: commonMethod.escapeHtml(nameObj.newname),
					update: plateListModel.isCustomBlockNeedUpdate(obj.id)
				});
				$('#sidebarbox-items').append(addHtml);
				$('#sidebarbox-items').scrollTop(9999);
			} else if (obj.event == 'del') {
				self.plateNames = plateListModel.removePlateName(self.plateNames, $('#view-a-data-id-' + obj.id).attr('title'));
				self.removePlate($('#items-data-id-' + obj.id));
			}
		},
		togglePlateList: function(e) {
			e = e || window.event;
			var $target = $(e.currentTarget);
			if ($target.hasClass('up-img')) {
				$target.removeClass('up-img').addClass('down-img').attr('title', '收起');
				$('#sidebarbox-items').slideUp();
			} else {
				$target.removeClass('down-img').addClass('up-img').attr('title', '展开');
				$('#sidebarbox-items').slideDown();
			}
		},
		toggleDynamicPlateList: function(e) {
			e = e || window.event;
			var $target = $(e.currentTarget);
			if ($target.hasClass('up-img')) {
				$target.removeClass('up-img').addClass('down-img').attr('title', '收起');
				$('#dynamic-sidebarbox-items').slideUp();
			} else {
				$target.removeClass('down-img').addClass('up-img').attr('title', '展开');
				$('#dynamic-sidebarbox-items').slideDown();
			}
		}
	});

	module.exports = PlateListView;
});
